﻿<%@ Page Title="Create Machine" Language="C#" MasterPageFile="~/MasterPage.master"
    AutoEventWireup="true" CodeFile="Create_Machine.aspx.cs" Inherits="admin_Create_Machine" %>

<%@ Import Namespace="Business" %>
<asp:Content ID="Head" ContentPlaceHolderID="head" runat="Server">
    <link href="../styles/admin.css" rel="stylesheet" type="text/css" />
    <link href="../styles/lytebox.css" rel="stylesheet" type="text/css" media="screen" />

    <script src="../javascripts/lytebox.js" type="text/javascript"></script>

    <script src="../javascripts/jquery-1.4.3.min.js" type="text/javascript"></script>

    <script src="../javascripts/jquery-ui-1.8.5.custom.min.js" type="text/javascript"></script>

</asp:Content>

<script runat="server">
    protected void InsertMachinType(object sender, EventArgs e)
    {
        var con = new CreateConn();
        var tbTypeName = (TextBox)FormViewMachine.FindControl("tbMachineTypeName");
        var typename = tbTypeName.Text;
        string insertQry = "Insert Into MachineType (machineType_name) values ('" + typename + "')";
        con.SQLConnDataTable(insertQry);

        var selectQry = "SELECT * FROM [MachineType] where MachineType_name = '" + typename + "'";
        con = new CreateConn();
        var dtMachineType = con.SQLConnDataTable(selectQry);
        while (dtMachineType.Rows.Count > 0)
        {
            var row = dtMachineType.Rows[0];
            int selectedId;
            Int32.TryParse(row["machineType_id"].ToString(), out selectedId);
            Session["MachineTypeID"] = selectedId;
            break;
        }
        Response.Redirect("Create_Machine.aspx");
    }
    
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div id="top_menu">
        <div id="help_button">
            help
        </div>
        <div id="logout">
            <asp:LoginStatus ID="LoginStatus1" runat="server" LogoutPageUrl="../Default.aspx"
                OnLoggingOut="LoginStatus1_LoggingOut" />
        </div>
    </div>
    <div id="page_title">
        ADMINISTRATION
    </div>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" runat="Server">
    <div id="left_content">
        <div class="menu">
            <ul>
                <li><a href="Home.aspx">Home</a></li>
                <li><a href="Mng_Client.aspx">Manage Clients</a></li>
                <li><a href="Mng_Site.aspx">Manage Sites</a></li>
                <li><a href="#" class="current">Create New Machine</a></li>
                <li><a href="Mng_Comp.aspx">Manage Components</a></li>
                <li><a href="Mng_Report.aspx">Manage Reports</a></li>
                <li><a href="Mng_WO.aspx">Manage Work Order</a></li>
                <li><a href="Mng_FaultsRecom.aspx">Manage Faults Recommendation</a></li>
            </ul>
        </div>
    </div>
    <!-- end of left content -->
    <div id="right_content">
        <div class="content_area">
            <h2>
                Create Machine
            </h2>
            <h3>
                <asp:Label ID="siteNameLabel" runat="server" Text="for site  : 'Site Name'" Visible="False"></asp:Label>
            </h3>
            <div class="form_box1">
                <table>
   <tr>
                        <asp:FormView ID="FormViewMachine" runat="server" DataKeyNames="machine_id" DataSourceID="MachineObjectDataSource"
                            DefaultMode="Insert" OnDataBound="FormViewMachine_DataBound">
                            <InsertItemTemplate>
                                <table>
                                    <asp:PlaceHolder ID="siteNamePlaceHolder" runat="server">
                                        <tr>
                                            <td class="label">
                                                Site Name:
                                            </td>
                                            <td colspan="5">
                                                <asp:DropDownList ID="siteNameDropDownList" runat="server" DataSourceID="SitesObjectDataSource"
                                                    DataTextField="siteName" DataValueField="site_id" SelectedValue='<%# Bind("site_id") %>'
                                                    CssClass="dropDownList">
                                                </asp:DropDownList>
                                                <asp:ObjectDataSource ID="SitesObjectDataSource" runat="server" OldValuesParameterFormatString="original_{0}"
                                                    SelectMethod="GetData" TypeName="DataAccess.i2iPortalTableAdapters.SitesOnClientsTableAdapter">
                                                </asp:ObjectDataSource>
                                            </td>
                                        </tr>
                                    </asp:PlaceHolder>
                                    <tr>
                                        <td>
                                        </td>
                                        <td colspan="5">
                                            <asp:RequiredFieldValidator ID="machineNameRequiredFieldValidator" runat="server"
                                                ErrorMessage="Machine Name is required." ControlToValidate="machineNameTextBox"
                                                ValidationGroup="FormViewMachine">
                                            </asp:RequiredFieldValidator>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="label">
                                            Machine Name:
                                        </td>
                                        <td colspan="5">
                                            <asp:TextBox ID="machineNameTextBox" runat="server" Text='<%# Bind("machineName") %>'
                                                CssClass="fields1" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="label">
                                            Machine Type
                                        </td>
                                        <td colspan="4">
                                            <asp:DropDownList ID="MachineTypeDropDownList" runat="server" DataSourceID="MachineTypeSqlDataSource"
                                                DataTextField="machineType_name" DataValueField="machineType_id" SelectedValue='<%# Bind("machineType_id") %>'
                                                CssClass="dropDownList">
                                            </asp:DropDownList>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="label">
                                        </td>
                                        <td colspan="4">
                                            <asp:TextBox ID="tbMachineTypeName" type="text" runat="server" CssClass="fields1" />
                                        </td>
                                        <td>
                                            <asp:Button ID="Button2" runat="server" Text="Add Machine Type" CssClass="buttons"
                                                OnClick="InsertMachinType" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="label">
                                            Photo File Name:
                                        </td>
                                        <td colspan="3">
                                            <asp:FileUpload ID="photoFileUpload" runat="server" CssClass="fields2" />
                                        </td>
                                        <td>
                                        </td>
                                        <td>
                                            <asp:Button ID="uploadButton" runat="server" Text="upload" OnClick="uploadButton_Click"
                                                CssClass="buttons" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                        </td>
                                        <td colspan="2">
                                            <asp:Image ID="photoImage" runat="server" Visible="False" />
                                        </td>
                                        <td colspan="2">
                                            <asp:Label ID="statusLabel" runat="server" CssClass="fields2"></asp:Label>
                                            <asp:TextBox ID="photoTextBox" runat="server" Text='<%# Bind("photo") %>' Visible="False"
                                                CssClass="fields2" />
                                        </td>
                                        <td valign="top">
                                            <asp:Button ID="removeButton" runat="server" Text="remove" OnClick="removeButton_Click"
                                                Visible="False" CssClass="buttons" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="label">
                                            Status:
                                        </td>
                                        <td colspan="5">
                                            <asp:DropDownList ID="statusDropDownList" runat="server" SelectedValue='<%# Bind("status") %>'
                                                CssClass="dropDownList">
                                                <asp:ListItem Text="Activated" Value="Activated"></asp:ListItem>
                                                <asp:ListItem Text="Deactivated" Value="Deactivated" Selected="True"></asp:ListItem>
                                            </asp:DropDownList>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="4">
                                        </td>
                                        <td class="Li_buttonC">
                                            <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                                                Text="Insert" OnClick="InsertButton_Click" />
                                        </td>
                                        <td class="Li_buttonC">
                                            <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                                                Text="Cancel" OnClick="InsertCancelButton_Click" />
                                        </td>
                                    </tr>
                                </table>
                            </InsertItemTemplate>
                        </asp:FormView>
                    </tr>
                </table>
            </div>
            <asp:SqlDataSource ID="MachineTypeSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                SelectCommand="SELECT * FROM [MachineType]"></asp:SqlDataSource>
            <asp:ObjectDataSource ID="MachineObjectDataSource" runat="server" OldValuesParameterFormatString="original_{0}"
                SelectMethod="GetData" TypeName="DataAccess.i2iPortalTableAdapters.MachinesTableAdapter"
                InsertMethod="Insert" OnInserted="OnMachineInserted">
                <InsertParameters>
                    <asp:Parameter Name="site_id" Type="Int32" />
                    <asp:Parameter Name="machineName" Type="String" />
                    <asp:Parameter Name="status" Type="String" />
                    <asp:Parameter Name="photo" Type="String" />
                    <asp:Parameter Name="machineType_id" Type="Int32" />
                </InsertParameters>
            </asp:ObjectDataSource>
        </div>
    </div>
    <!-- end of right content -->
</asp:Content>
